﻿// Copyright richyp 2009
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace Richyp.Bodger.UI {
    public partial class PrintPreviewForm : Form {
        public PrintPreviewForm() {
            InitializeComponent();
        }
        public PrintPreviewForm(CodexFile codex, DataGridView list) {
            if (codex == null)
            {
                return;
            }

            InitializeComponent();
            this.codexFile = codex;
            foreach (DataGridViewRow row in list.Rows) {
                if (!(row is CategoryRow)) {
                    entries.Add((ListEntry)row.Tag);
                }
            }
            this.printDocument.PrintPage += new System.Drawing.Printing.PrintPageEventHandler(printDocument_PrintPage);
            this.printPreviewControl.AutoZoom = true;
        }

        private int entryHeight = 50;
        private int current = 0;
        private int page = 1;
        private string currentCategory = "";
        private int pageCount = 0;

        Font footer = new Font("Arial", 8);
        Font unitHeaderFont = new Font("Arial", 12, FontStyle.Bold);
        Font unitEntry = new Font("Arial", 9);
        Font unitWargear = new Font("Arial", 8, FontStyle.Italic);
        Font unitInvlunerable = new Font("Arial", 7);
        SolidBrush brush = new SolidBrush(Color.Black);
        SolidBrush dark = new SolidBrush(Color.DarkBlue);

        void printDocument_PrintPage(object sender, System.Drawing.Printing.PrintPageEventArgs e) {
            bool endOfPage = false;
            Image watermark = null;
            pageCount++;

            string wfilename = "watermark";
            string[] wtypes = new string[] { ".png", ".gif", ".jpg", ".bmp" };
            foreach (string type in wtypes) {
                string path = Application.StartupPath + "/Data/Game System/";
                path += codexFile.System + "/images/";
                path += wfilename + type;
                if (System.IO.File.Exists(path)) {
                    watermark = Image.FromFile(path);
                    break;
                }
            }
            if (watermark != null) {                
                int xOffset = (e.PageBounds.Width / 2) - (e.PageBounds.Width / 2);
                int yOffset = (e.PageBounds.Height / 2) - (e.PageBounds.Height / 2);
                e.Graphics.DrawImage(watermark, xOffset, yOffset);
            }
            int y = e.MarginBounds.Y;
            int x = e.MarginBounds.X;
            int bottom = e.MarginBounds.Y + e.MarginBounds.Height;
            int right = e.MarginBounds.X + e.MarginBounds.Width;

            if (page == 1) {
                int totalPoints = 0;
                foreach (ListEntry en in this.entries) {
                    foreach (Unit u in en.Units) {
                        totalPoints += u.GetTotalCost();
                    }
                    totalPoints += en.BaseEntry.CostOffset;
                }
                e.Graphics.DrawString(this.codexFile.UserListName + ": " + this.codexFile.Name, unitHeaderFont, brush, x, y);
                e.Graphics.DrawString(totalPoints + " pts", unitHeaderFont, Brushes.DarkBlue, right - 80, y);
                y += 50;
            }
            while (!endOfPage) {
                if (current > entries.Count-1) {
                    endOfPage = true;
                } else {
                    ListEntry entry = entries[current];
                    if (entry.CurrentCategory!= this.currentCategory) 
                    {
                        Image icon = null;
                        string filename = entry.BaseEntry.Category.Substring(entry.BaseEntry.Category.IndexOf(".") + 1);
                        string[] types = new string[] { ".png", ".gif", ".jpg", ".bmp" };
                        foreach (string type in types)
                        {
                            string path = Application.StartupPath + "/Data/Game System/";
                            path += codexFile.System + "/images/categories/";
                            path += filename + type;
                            if (System.IO.File.Exists(path))
                            {
                                icon = Image.FromFile(path);
                                break;
                            }
                        }
                        int offset = x;
                        if (icon != null) {
                            offset += 32;                                        
                            e.Graphics.DrawImage(icon, x, y, 32, 32);                          
                        }
                        y += 5;
                        currentCategory = entry.CurrentCategory;
                        e.Graphics.DrawString(currentCategory.Substring(currentCategory.IndexOf(".")+1), unitHeaderFont, Brushes.Black, offset, y);
                        e.Graphics.DrawLine(Pens.Black, offset + 5, y + 20, right, y + 20);
                        y += 35;
                    }               

                    PrintUnitDescription(entry, x, ref y, right, e);

                    // Test to see if the next entry will overflow the page
                    if (current + 1 != entries.Count())
                    {
                        int nextEntrySize = (entries[current + 1].DistinctUnits * 54);

                        if (entries[current + 1].CurrentCategory != this.currentCategory)
                        {
                            nextEntrySize += 35;
                        }

                        if (y + nextEntrySize > bottom)
                        {
                            e.Graphics.DrawString("Page " + page, footer, brush, x, bottom + 10);
                            endOfPage = true;
                            e.HasMorePages = true;
                            page++;
                        }
                    }

                    current++;
                    y+= entryHeight;
                }
            }

            if (!e.HasMorePages) {
                e.Graphics.DrawString("Page " + page, footer, brush, x, bottom + 10);              
            }
        }

        private void PrintUnitDescription(ListEntry entry, int x,ref int y, int right, System.Drawing.Printing.PrintPageEventArgs e)
        {
            StringFormat centered = new StringFormat();
            centered.Alignment = StringAlignment.Center;
            int attributeWidth = 35;
            int nameWidth = 167;
            int typeWidth = 130;
            int saveWidth = 32;
            int pointsWidth = 45;

            // Unit Name/Point Cost
            e.Graphics.DrawString(entry.BaseEntry.Name, unitHeaderFont, brush, x, y);
            e.Graphics.DrawLine(Pens.DarkGray, x + 5, y + 18, right, y + 18);
            int total = 0;
            foreach (Unit unit in entry.Units)
            {
                total += unit.GetTotalCost();
            }
            total += entry.BaseEntry.CostOffset;

            e.Graphics.DrawString(total + " pts", unitHeaderFont, brush, right - 80, y);

            e.Graphics.DrawRectangle(new Pen(Color.Gray), new Rectangle(x + 5, y + 22, 25, 18));
            e.Graphics.DrawRectangle(new Pen(Color.Gray), new Rectangle(x + 30, y + 22, nameWidth, 18));
            e.Graphics.DrawRectangle(new Pen(Color.Gray), new Rectangle(x + 30 + nameWidth, y + 22, typeWidth, 18));
            e.Graphics.DrawRectangle(new Pen(Color.Gray), new Rectangle(x + 30 + nameWidth + typeWidth, y + 22, attributeWidth, 18));
            e.Graphics.DrawRectangle(new Pen(Color.Gray), new Rectangle(x + 30 + nameWidth + typeWidth + 1 * attributeWidth, y + 22, attributeWidth, 18));
            e.Graphics.DrawRectangle(new Pen(Color.Gray), new Rectangle(x + 30 + nameWidth + typeWidth + 2 * attributeWidth, y + 22, attributeWidth, 18));
            e.Graphics.DrawRectangle(new Pen(Color.Gray), new Rectangle(x + 30 + nameWidth + typeWidth + 3 * attributeWidth, y + 22, attributeWidth, 18));
            e.Graphics.DrawRectangle(new Pen(Color.Gray), new Rectangle(x + 30 + nameWidth + typeWidth + 4 * attributeWidth, y + 22, attributeWidth, 18));
            e.Graphics.DrawRectangle(new Pen(Color.Gray), new Rectangle(x + 30 + nameWidth + typeWidth + 5 * attributeWidth, y + 22, attributeWidth, 18));
            e.Graphics.DrawRectangle(new Pen(Color.Gray), new Rectangle(x + 30 + nameWidth + typeWidth + 6 * attributeWidth, y + 22, attributeWidth, 18));
            e.Graphics.DrawRectangle(new Pen(Color.Gray), new Rectangle(x + 30 + nameWidth + typeWidth + 7 * attributeWidth, y + 22, attributeWidth, 18));
            e.Graphics.DrawRectangle(new Pen(Color.Gray), new Rectangle(x + 30 + nameWidth + typeWidth + 8 * attributeWidth, y + 22, saveWidth, 18));


            e.Graphics.DrawString("#", unitEntry, brush, new Rectangle(x + 5, y + 24, 25, 17), centered);
            e.Graphics.DrawString("Name", unitEntry, brush, new Rectangle(x + 30, y + 24, nameWidth, 17), centered);
            e.Graphics.DrawString("Type", unitEntry, brush, new Rectangle(x + 30 + nameWidth, y + 24, typeWidth, 17), centered);
            if (entry.Units[0].Type == UnitClass.Vehicle)
            {
                e.Graphics.DrawString("BS", unitEntry, brush, new Rectangle(x + 30 + nameWidth + typeWidth + 1 * attributeWidth, y + 24, attributeWidth, 17), centered);
                e.Graphics.DrawString("FA", unitEntry, brush, new Rectangle(x + 30 + nameWidth + typeWidth + 3 * attributeWidth, y + 24, attributeWidth, 17), centered);
                e.Graphics.DrawString("SA", unitEntry, brush, new Rectangle(x + 30 + nameWidth + typeWidth + 4 * attributeWidth, y + 24, attributeWidth, 17), centered);
                e.Graphics.DrawString("RA", unitEntry, brush, new Rectangle(x + 30 + nameWidth + typeWidth + 5 * attributeWidth, y + 24, attributeWidth, 17), centered);
            }
            else if (entry.Units[0].Type == UnitClass.Walker)
            {
                e.Graphics.DrawString("WS", unitEntry, brush, new Rectangle(x + 30 + nameWidth + typeWidth, y + 24, attributeWidth, 17), centered);
                e.Graphics.DrawString("BS", unitEntry, brush, new Rectangle(x + 30 + nameWidth + typeWidth + 1 * attributeWidth, y + 24, attributeWidth, 17), centered);
                e.Graphics.DrawString("S", unitEntry, brush, new Rectangle(x + 30 + nameWidth + typeWidth + 2 * attributeWidth, y + 24, attributeWidth, 17), centered);
                e.Graphics.DrawString("FA", unitEntry, brush, new Rectangle(x + 30 + nameWidth + typeWidth + 3 * attributeWidth, y + 24, attributeWidth, 17), centered);
                e.Graphics.DrawString("SA", unitEntry, brush, new Rectangle(x + 30 + nameWidth + typeWidth + 4 * attributeWidth, y + 24, attributeWidth, 17), centered);
                e.Graphics.DrawString("RA", unitEntry, brush, new Rectangle(x + 30 + nameWidth + typeWidth + 5 * attributeWidth, y + 24, attributeWidth, 17), centered);
                e.Graphics.DrawString("I", unitEntry, brush, new Rectangle(x + 30 + nameWidth + typeWidth + 6 * attributeWidth, y + 24, attributeWidth, 17), centered);
                e.Graphics.DrawString("A", unitEntry, brush, new Rectangle(x + 30 + nameWidth + typeWidth + 7 * attributeWidth, y + 24, attributeWidth, 17), centered);
            }
            else
            {
                e.Graphics.DrawString("WS", unitEntry, brush, new Rectangle(x + 30 + nameWidth + typeWidth, y + 24, attributeWidth, 17), centered);
                e.Graphics.DrawString("BS", unitEntry, brush, new Rectangle(x + 30 + nameWidth + typeWidth + 1 * attributeWidth, y + 24, attributeWidth, 17), centered);
                e.Graphics.DrawString("S", unitEntry, brush, new Rectangle(x + 30 + nameWidth + typeWidth + 2 * attributeWidth, y + 24, attributeWidth, 17), centered);
                e.Graphics.DrawString("T", unitEntry, brush, new Rectangle(x + 30 + nameWidth + typeWidth + 3 * attributeWidth, y + 24, attributeWidth, 17), centered);
                e.Graphics.DrawString("W", unitEntry, brush, new Rectangle(x + 30 + nameWidth + typeWidth + 4 * attributeWidth, y + 24, attributeWidth, 17), centered);
                e.Graphics.DrawString("I", unitEntry, brush, new Rectangle(x + 30 + nameWidth + typeWidth + 5 * attributeWidth, y + 24, attributeWidth, 17), centered);
                e.Graphics.DrawString("A", unitEntry, brush, new Rectangle(x + 30 + nameWidth + typeWidth + 6 * attributeWidth, y + 24, attributeWidth, 17), centered);
                e.Graphics.DrawString("Ld", unitEntry, brush, new Rectangle(x + 30 + nameWidth + typeWidth + 7 * attributeWidth, y + 24, attributeWidth, 17), centered);
                e.Graphics.DrawString("Sv", unitEntry, brush, new Rectangle(x + 30 + nameWidth + typeWidth + 8 * attributeWidth, y + 24, saveWidth, 17), centered);
            }

            y += 18;


            string[] parts = entry.GetDescription(true, false).Split(new char[] { ',' });
            foreach (string part in parts)
            {
                string[] details = part.Split(new char[] { ':' });
                string[] gear = details[0].Split(new char[] { '(', ')' });

                // UnitType Description
                string unitName = gear[0].Substring(gear[0].IndexOf('x') + 1).Trim();
                Unit unit = entry.GetUnitByName(unitName);

                e.Graphics.DrawRectangle(new Pen(Color.Gray), new Rectangle(x + 5, y + 22, 25, 18));
                e.Graphics.DrawRectangle(new Pen(Color.Gray), new Rectangle(x + 30, y + 22, nameWidth, 18));
                e.Graphics.DrawRectangle(new Pen(Color.Gray), new Rectangle(x + 30 + nameWidth, y + 22, typeWidth, 18));
                e.Graphics.DrawRectangle(new Pen(Color.Gray), new Rectangle(x + 30 + nameWidth + typeWidth, y + 22, attributeWidth, 18));
                e.Graphics.DrawRectangle(new Pen(Color.Gray), new Rectangle(x + 30 + nameWidth + typeWidth + 1 * attributeWidth, y + 22, attributeWidth, 18));
                e.Graphics.DrawRectangle(new Pen(Color.Gray), new Rectangle(x + 30 + nameWidth + typeWidth + 2 * attributeWidth, y + 22, attributeWidth, 18));
                e.Graphics.DrawRectangle(new Pen(Color.Gray), new Rectangle(x + 30 + nameWidth + typeWidth + 3 * attributeWidth, y + 22, attributeWidth, 18));
                e.Graphics.DrawRectangle(new Pen(Color.Gray), new Rectangle(x + 30 + nameWidth + typeWidth + 4 * attributeWidth, y + 22, attributeWidth, 18));
                e.Graphics.DrawRectangle(new Pen(Color.Gray), new Rectangle(x + 30 + nameWidth + typeWidth + 5 * attributeWidth, y + 22, attributeWidth, 18));
                e.Graphics.DrawRectangle(new Pen(Color.Gray), new Rectangle(x + 30 + nameWidth + typeWidth + 6 * attributeWidth, y + 22, attributeWidth, 18));
                e.Graphics.DrawRectangle(new Pen(Color.Gray), new Rectangle(x + 30 + nameWidth + typeWidth + 7 * attributeWidth, y + 22, attributeWidth, 18));
                e.Graphics.DrawRectangle(new Pen(Color.Gray), new Rectangle(x + 30 + nameWidth + typeWidth + 8 * attributeWidth, y + 22, saveWidth, 18));

                e.Graphics.DrawString(gear[0].Substring(0, gear[0].IndexOf('x') - 1).Trim(), unitEntry, brush, new Rectangle(x + 5, y + 24, 25, 17), centered);
                e.Graphics.DrawString(unitName, unitEntry, brush, new Rectangle(x + 30, y + 24, nameWidth, 17), centered);
                e.Graphics.DrawString(unit.ClassToString(unit.Type), unitEntry, brush, new Rectangle(x + 30 + nameWidth, y + 24, typeWidth, 17), centered);
                if (unit.Type == UnitClass.Vehicle)
                {
                    e.Graphics.DrawString(unit.GetAttributeString("BS"), unitEntry, brush, new Rectangle(x + 30 + nameWidth + typeWidth + 1 * attributeWidth, y + 24, attributeWidth, 17), centered);
                    e.Graphics.DrawString(unit.GetAttributeString("FA"), unitEntry, brush, new Rectangle(x + 30 + nameWidth + typeWidth + 3 * attributeWidth, y + 24, attributeWidth, 17), centered);
                    e.Graphics.DrawString(unit.GetAttributeString("SA"), unitEntry, brush, new Rectangle(x + 30 + nameWidth + typeWidth + 4 * attributeWidth, y + 24, attributeWidth, 17), centered);
                    e.Graphics.DrawString(unit.GetAttributeString("RA"), unitEntry, brush, new Rectangle(x + 30 + nameWidth + typeWidth + 5 * attributeWidth, y + 24, attributeWidth, 17), centered);
                }
                else if (unit.Type == UnitClass.Walker)
                {
                    e.Graphics.DrawString(unit.GetAttributeString("WS"), unitEntry, brush, new Rectangle(x + 30 + nameWidth + typeWidth, y + 24, attributeWidth, 17), centered);
                    e.Graphics.DrawString(unit.GetAttributeString("BS"), unitEntry, brush, new Rectangle(x + 30 + nameWidth + typeWidth + 1 * attributeWidth, y + 24, attributeWidth, 17), centered);
                    e.Graphics.DrawString(unit.GetAttributeString("S"), unitEntry, brush, new Rectangle(x + 30 + nameWidth + typeWidth + 2 * attributeWidth, y + 24, attributeWidth, 17), centered);
                    e.Graphics.DrawString(unit.GetAttributeString("FA"), unitEntry, brush, new Rectangle(x + 30 + nameWidth + typeWidth + 3 * attributeWidth, y + 24, attributeWidth, 17), centered);
                    e.Graphics.DrawString(unit.GetAttributeString("SA"), unitEntry, brush, new Rectangle(x + 30 + nameWidth + typeWidth + 4 * attributeWidth, y + 24, attributeWidth, 17), centered);
                    e.Graphics.DrawString(unit.GetAttributeString("RA"), unitEntry, brush, new Rectangle(x + 30 + nameWidth + typeWidth + 5 * attributeWidth, y + 24, attributeWidth, 17), centered);
                    e.Graphics.DrawString(unit.GetAttributeString("I"), unitEntry, brush, new Rectangle(x + 30 + nameWidth + typeWidth + 6 * attributeWidth, y + 24, attributeWidth, 17), centered);
                    e.Graphics.DrawString(unit.GetAttributeString("A"), unitEntry, brush, new Rectangle(x + 30 + nameWidth + typeWidth + 7 * attributeWidth, y + 24, attributeWidth, 17), centered);
                }
                else
                {
                    e.Graphics.DrawString(unit.GetAttributeString("WS"), unitEntry, brush, new Rectangle(x + 30 + nameWidth + typeWidth, y + 24, attributeWidth, 17), centered);
                    e.Graphics.DrawString(unit.GetAttributeString("BS"), unitEntry, brush, new Rectangle(x + 30 + nameWidth + typeWidth + 1 * attributeWidth, y + 24, attributeWidth, 17), centered);
                    e.Graphics.DrawString(unit.GetAttributeString("S"), unitEntry, brush, new Rectangle(x + 30 + nameWidth + typeWidth + 2 * attributeWidth, y + 24, attributeWidth, 17), centered);
                    e.Graphics.DrawString(unit.GetAttributeString("T"), unitEntry, brush, new Rectangle(x + 30 + nameWidth + typeWidth + 3 * attributeWidth, y + 24, attributeWidth, 17), centered);
                    e.Graphics.DrawString(unit.GetAttributeString("W"), unitEntry, brush, new Rectangle(x + 30 + nameWidth + typeWidth + 4 * attributeWidth, y + 24, attributeWidth, 17), centered);
                    e.Graphics.DrawString(unit.GetAttributeString("I"), unitEntry, brush, new Rectangle(x + 30 + nameWidth + typeWidth + 5 * attributeWidth, y + 24, attributeWidth, 17), centered);
                    e.Graphics.DrawString(unit.GetAttributeString("A"), unitEntry, brush, new Rectangle(x + 30 + nameWidth + typeWidth + 6 * attributeWidth, y + 24, attributeWidth, 17), centered);
                    e.Graphics.DrawString(unit.GetAttributeString("LD"), unitEntry, brush, new Rectangle(x + 30 + nameWidth + typeWidth + 7 * attributeWidth, y + 24, attributeWidth, 17), centered);

                    string invulString = unit.GetAttributeString("INV");

                    if (invulString != "")
                    {
                        StringFormat rightAlign = new StringFormat();
                        rightAlign.Alignment = StringAlignment.Far;

                        if (unit.GetAttributeValue("SV") == 0)
                        {
                            e.Graphics.DrawString("-", unitEntry, brush, new Rectangle(x + 30 + nameWidth + typeWidth + 8 * attributeWidth, y + 24, 20, 17), rightAlign);
                        }
                        else
                        {
                            e.Graphics.DrawString(unit.GetAttributeString("SV"), unitEntry, brush, new Rectangle(x + 30 + nameWidth + typeWidth + 8 * attributeWidth, y + 24, 20, 17), rightAlign);
                        }
                        e.Graphics.DrawString(invulString, unitInvlunerable, dark, new Rectangle(x + 30 + nameWidth + typeWidth + 8 * attributeWidth + saveWidth/2, y + 23, 20, 10));
                        //"/" + unit.GetAttributeValue("INV").ToString() + "+"
                    }

                    else
                    {
                        if (unit.GetAttributeValue("SV") == 0)
                        {
                            e.Graphics.DrawString("-", unitEntry, brush, new Rectangle(x + 30 + nameWidth + typeWidth + 8 * attributeWidth, y + 24, saveWidth, 17), centered);
                        }
                        else
                        {
                            e.Graphics.DrawString(unit.GetAttributeString("SV"), unitEntry, brush, new Rectangle(x + 30 + nameWidth + typeWidth + 8 * attributeWidth, y + 24, saveWidth, 17), centered);
                        }

                    }
                }

                // UnitType Point Cost
                e.Graphics.DrawRectangle(new Pen(Color.Gray), new Rectangle(x + 30 + nameWidth + typeWidth + 8 * attributeWidth + saveWidth, y + 22, pointsWidth, 18));
                e.Graphics.DrawString(details[1].Replace(" ", ""), unitEntry, brush, new Rectangle(x + 30 + nameWidth + typeWidth + 8 * attributeWidth + saveWidth, y + 24, pointsWidth, 17), centered);
                

                // Wargear lines
                if (gear.Length > 1)
                {
                    int height = 1;
                    SizeF size = e.Graphics.MeasureString(gear[1], unitWargear);
                    height = (int)Math.Ceiling(size.Width / 652.0);
                    e.Graphics.DrawRectangle(new Pen(Color.Gray), new Rectangle(x + 5, y + 40, 25 + nameWidth + typeWidth + 8 * attributeWidth + saveWidth, 18 * height));
                    e.Graphics.DrawString("  - " + gear[1], unitWargear, dark, new Rectangle(x + 5, y + 42, 652, 18 * height));
                    y += 18 * height;
                }

                y += 18;
            }
        }

        public System.Drawing.Printing.PrintDocument Document {
            get {
                return this.printDocument;
            }
        }

        private CodexFile codexFile = null;
        public CodexFile CodexFile
        {
            get { return codexFile; }
        }

        private List<ListEntry> entries = new List<ListEntry>();

        private void buttonPrint_Click(object sender, EventArgs e)
        {
            PrintDialog dialog = new PrintDialog();
            dialog.Document = this.printPreviewControl.Document;
            if (dialog.ShowDialog() == DialogResult.OK)
            {
                this.current = 0;
                this.page = 1;
                this.printPreviewControl.Document.Print();
            }

            this.Close();
        }

        private void buttonClose_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void Zoom_Click(object sender, EventArgs e)
        {
            if (this.zoomAmount.Text.ToUpper().Trim() == "AUTO")
            {
                this.printPreviewControl.AutoZoom = true;
            }
            
            double zoom;
            if (double.TryParse(this.zoomAmount.Text.Replace('%', ' '), out zoom))
            {
                this.printPreviewControl.AutoZoom = false;
                this.printPreviewControl.Zoom = zoom/100;
            }
        }

        private void pageSelector_ValueChanged(object sender, EventArgs e)
        {
            if (pageSelector.Value < 1)
            {
                pageSelector.Value = 1;
            }

            if (pageSelector.Value > pageCount)
            {
                pageSelector.Value = pageCount;
            }

            this.printPreviewControl.StartPage = (int)pageSelector.Value - 1;
        }

        private void printPreviewControl_Click(object sender, EventArgs e)
        {
            if (((MouseEventArgs)e).Button == MouseButtons.Left)
            {
                if (this.printPreviewControl.Zoom < 4)
                {
                    this.printPreviewControl.Zoom += 0.2;
                }
                return;
            }

            if (this.printPreviewControl.Zoom > 0.2)
            {
                this.printPreviewControl.Zoom -= 0.20;
            }
        }
    }
}
